package linter.controller.model;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import linter.POJO.DTO.UserDTO;
import linter.custom.ResultVO;
import linter.service.ModelDataDisposeService;
import linter.service.UserService;
import linter.utils.JwtUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.SecurityUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

import static linter.custom.CustomResultType.USER_NOT_EXIST;

/**
 * @author 北煜
 */
@Slf4j
@RestController
@Api(tags = "数据清理")
@RequestMapping("/DataDispose")
public class DataDisposeController {

    @Resource
    UserService userService;
    @Resource
    ModelDataDisposeService modelDataDisposeService;

    @GetMapping("/show/getUserByUsername/{username}")
    @ApiOperation("根据用户名查找用户")
    public ResultVO<UserDTO> getUserByUsername(@PathVariable String username) {
        UserDTO userDTO = userService.getUserByUsername(username);
        return ResultVO.success(userDTO);
    }

    @PostMapping("/dispose")
    @ApiOperation("数据清理")
    public ResultVO<?> dispose(Integer disposeType, String dataName, Integer nNeighbors){
        String username = JwtUtils.getUserName((String) SecurityUtils.getSubject().getPrincipal());
        Long uuid = userService.getIdByUsername(username);
        if (uuid != null) { return ResultVO.success(modelDataDisposeService.dispose(uuid, dataName, disposeType, nNeighbors)); }
        return ResultVO.error(USER_NOT_EXIST);
    }
}
